#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int motor_control(unsigned status) {
    int fd_motor = open("/dev/motor_drv", O_WRONLY);
    if (fd_motor == -1) {
        perror("open motor");
        return -1;
    }

    unsigned char motorstatus = (status != 0) ? 1 : 0;  // 确保值为0或1
    if (write(fd_motor, &motorstatus, 1) != 1) {
        perror("write motor");
        close(fd_motor);
        return -1;
    }

    close(fd_motor);
    return 0;
}
